﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClientAppViaWebService.ClubLogicServiceRef;

namespace ClientAppViaWebService.Forms
{
    public partial class ClubEditForm  : OrganizationalDivisionEditForm
    {
        private readonly Int32 ClassID = 12;
        private ClubLogicService clubLogicService;

        #region Properties.

        public string Room
        {
            get { return txtRoom.Text; }
            set { txtRoom.Text = value; }
        }

        public String Speciallity
        {
            get { return txtSpeciallity.Text; }
            set { txtSpeciallity.Text = value; }
        }       

        #endregion

        public ClubEditForm()
        {
            InitializeComponent();
            clubLogicService = new ClubLogicService();
        }

        protected override void SetFormProperties(Object _object)
        {   
            Club obj = (_object as Club);
            ID = obj.ID;
            EXT_ID = obj.EXT_ID;
            ParentId = obj.PARENT_ID;
            Class = obj.CLASS_ID;
            ObjName = obj.NAME;
            BossName = obj.BOSS_ID;
            DateCreated = obj.DATE_CREATED;
            Description = obj.DESCRIPTION;
            Email = obj.EMAIL;
            Slogan = obj.SLOGAN;
            Room  = obj.ROOM_ID;
            Speciallity= obj.SPECIALITY;
        }

        protected override Object RetrieveFormProperties()
        {
            Club obj = new Club();
            obj.ID = ID;
            obj.EXT_ID = EXT_ID;
            obj.PARENT_ID = ParentId;
            obj.CLASS_ID = ClassID;
            obj.NAME = ObjName;
            obj.DataBaseName = DataBaseName;
            obj.BOSS_ID = BossName;
            obj.DATE_CREATED = DateCreated;
            obj.DESCRIPTION = Description;
            obj.EMAIL = Email;
            obj.SLOGAN = Slogan;
            obj.ROOM_ID = Room;
            obj.SPECIALITY = Speciallity;
            return obj;
        }

        protected override void LoadEditFormData(int parentNodeID)
        {           
            Club p = clubLogicService.SelectClub_By_DataBase_And_Id(DataBaseName, parentNodeID);
            SetFormProperties(p);
        }

        protected override void UpdateEntity()
        {           
            Club obj = RetrieveFormProperties() as Club;
            clubLogicService.UpdateClub(obj);
        }

        protected override void InsertEntity()
        {           
            Club obj = RetrieveFormProperties() as Club;
            clubLogicService.InsertClub(obj);
        }
    }
}
